﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace TooltracePC
{
   
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
        }


        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DataTable dtUser = null;
            dbAdmin dbAdmin1 = new dbAdmin();
            string UserName = this.tbUserName.Text;
            string PassWord = this.tbPassWord.Text;
            string PassWordMd5 = "";
            if(string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(PassWord))
            {
                MessageBox.Show("用户名或密码不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            dtUser = dbAdmin1.getAdminByName(UserName);
            if (dtUser == null)
            {
                MessageBox.Show("没有该用户!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (dtUser.Rows.Count == 0)
            {
                MessageBox.Show("没有该用户!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            encode enMd5 = new encode();

            PassWordMd5 = dtUser.Rows[0]["p"].ToString();
            PassWord = enMd5.strToMd5(PassWord);
            dtUser.Clear();

            if(PassWordMd5 != PassWord)
            {
                MessageBox.Show("密码错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.DialogResult = DialogResult.OK;
           // this.Owner.Show();
            //this.Close();
            frmMain frmmain = new frmMain();
            this.Hide();
            frmmain.Show();
            //this.Close();
            //frm.Show();
            //this.Hide();
            //this.Close();

        }

        private void btnCan_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {

        }
        



    }
}
